perm filename COUNT.LSP[F78,JMC] blob
sn#404666 filedate 1978-12-19 generic text, type C, neo UTF8
COMMENT ā VALID 00002 PAGES
C REC PAGE DESCRIPTION
C00001 00001
C00002 00002 (defun comment (x) '(comment suppressed))
C00004 ENDMK
Cā;
(defun comment (x) '(comment suppressed))
(comment '(In connection with Cartwrights complete recursive functions,
we try to make a derived function that counts the number of recursive
calls in a call-by-name evaluation. We work with flat[x,u] and
the Cadiou function f(x,y) ā if x=0 then 0 else f(x-1,f(y+1,x)). The
arguments of the original function are replaced by pairs, consisting
of a domain element and a non-negative integer, and the value of the
function is a pair consisting of the value and the number of recursive
calls.)
(defun flat1 (x u) (cond ((atom (car x)) (cons (cons (car x) (car u))
(plus (cdr x) (cdr u))))
(t (cons
(car
(flat1 (cons (caar x) (cdr x))
(cons (car (flat1 (cons (cdar x) (cdr x)) u))
(add1 (cdr (flat1 (cons (cdar x) (cdr x)) u)))))
)
(add1 (cdr
(flat1 (cons (caar x) (cdr x))
(cons (car (flat1 (cons (cdar x) (cdr x)) u))
(add1 (cdr (flat1 (cons (cdar x) (cdr x)) u)))))
))))))